﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{
    public class ImageTexture : Texture
    {
        System.Drawing.Bitmap textureMap;


        public ImageTexture(System.Drawing.Image image)                 // Constructor takes any sceneImage and turns it into a bitmap.
        {
            this.textureMap = new System.Drawing.Bitmap(image);
        }


        #region Texture Members
                                                                
        public Color textureAt(P2 p)                            // takes a P2 p and returns the color of the texture at the 
        {                                                       // the location p. (dark magic math).
            P2 p2 = new P2(Math.Min(p.x * textureMap.Width,textureMap.Width -1 ),Math.Min( p.y * textureMap.Height,textureMap.Height-1));
            System.Drawing.Color color = textureMap.GetPixel((int)p2.x, (int)p2.y);
            return new Color(color.R/256.0f,color.G/256.0f,color.B/256.0f);
        }

        #endregion
    }
}
